package org.crazyit.activiti_d1._2_AddGroup;

import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.identity.Group;

import java.util.UUID;

public class AddGroupError {

    public static void main(String[] args) {

        //1. 创建默认的流程引擎
        ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

        //2. 得到身份服务组件实例
        IdentityService identityService = engine.getIdentityService();

        //3. 生成UUID
        String genId = "1";

        //4. 调用newGroup() 方法创建Group 实例
        Group group1 = identityService.newGroup(genId);
        group1.setName("经理组");
        group1.setType("manager");
        group1.setId("1");

        //5. 调用newGroup() 方法创建相同的Group 实例
        Group group2 = identityService.newGroup(genId);
        group2.setName("经理组");
        group2.setType("manager");
        group2.setId("1");

        //6. 保存到数据库
        identityService.saveGroup(group1);
        identityService.saveGroup(group2);

        //7. 查询用户组
        Group data = identityService.createGroupQuery().groupId(genId).singleResult();

        //8. 输出结果
        System.out.println("Group ID: " + data.getId() + ", Name: " + data.getName());

    }

}
